package sist.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import sist.bean.MemberCheckBean;
import sist.dao.ScottDao;


@Component
@Controller
public class ValidateController {
	@Resource(name="scottDao")
	private ScottDao dao;
	
	@RequestMapping(value="/htmlView/validateCheck.do")
	public String validateFunction(@RequestParam(value="place")String tel){
		System.out.println(tel);
		return "htmlView/formResult2";
	}
	
	@ExceptionHandler(NullPointerException.class)
	public String handlerNullPointException(){
		return "error/nullException";
	}
	
	@ExceptionHandler(ArithmeticException.class)
	public String handlerArithmeticException(){
		return "error/arithmeticException";
	}
	
	@RequestMapping(value="account/formValidate.do")
	public ModelAndView validateCheckFun(@ModelAttribute("command")MemberCheckBean bean,BindingResult result)throws Throwable{
		/*String str=null;
		str.charAt(0);*/
		
		/*int rs=10/0;*/
		ModelAndView mv=new ModelAndView();
		new MemberInfoValidate().validate(bean, result);
		if(result.hasErrors()){
			mv.setViewName("/account/form");
			return mv;
		}else{
			dao.insertMemberCheck(bean);
			mv.addObject("memberList", dao.getMemberCheck());
			mv.setViewName("/account/formResult");
			return mv;
		}
		
	}
}
